package com.bfxy.disruptor;

import java.util.Arrays;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.Executors;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.Semaphore;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.locks.LockSupport;

public class Review {

	public static void main(String[] args) throws Exception {
		
		ReentrantLock reentrantLock = new ReentrantLock(true);
		
		Ticket t = new Ticket(reentrantLock);//创建一个线程任务对象。   
        Thread t1 = new Thread(t);  
        Thread t2 = new Thread(t);  
        Thread t3 = new Thread(t);  
        t1.start();  
        t2.start();  
        t3.start(); 
        
//        System.exit(0);
	}
	
	  
}

class Ticket implements Runnable {
    // 当前拥有的票数
    private int num = 2;
    ReentrantLock lock = null;
    public Ticket(ReentrantLock reentrantLock){
    	this.lock = reentrantLock;
    }
    public void run() {
        while (true) {
            lock.lock();
            if (num > 0) {
                System.out.println(Thread.currentThread().getName() + ".....sale...." + num--);
            }
            lock.unlock();
        }
    }
}
